#ifndef __CALLBACK_VIDEO_CODEC_AVI_H__
#define __CALLBACK_VIDEO_CODEC_AVI_H__

/****************************************************************************
 *                      C O N S T A N T S                                   *
 ****************************************************************************/
// common
#define JPEG_IMG_FORMAT_422					0x21
#define JPEG_IMG_FORMAT_420					0x22

#define ENABLE_REAR_FUNC					1

#define ENABLE_DOUBLE_JPEG					1 // Don't Disable

#define ENABLE_REAR_SENSOR_FROM_HOST_UVC	1

#if ENABLE_REAR_SENSOR_FROM_HOST_UVC
#define HOST_UVC_DECODE_FORMAT_GP420		1//0	// 0: YUYV 1: GP420
//#define REAR_SENSOR_WIDTH					FRAME_WIDTH
//#define REAR_SENSOR_HEIGHT					FRAME_HEIGHT
#else
#define HOST_UVC_DECODE_FORMAT_GP420		0	// 0: YUYV 1: GP420
#endif // ENABLE_REAR_SENSOR_FROM_HOST_UVC

#define HOST_UVC_DECODE_USE_FIFO_MODE		 0 // 1

#if 1//HOST_UVC_DECODE_USE_FIFO_MODE
#define JPEG_DEC_FIFO_LINE					32
#endif

// FRONT
#define FIFO_FRONT_OUTPUT_BUFFER_CNT			6
#define FIFO_FRONT_OUTPUT_BUFFER_CNT_1080P		6
#define FIFO_FRONT_OUTPUT_BUFFER_CNT_1080FHD	6

#if (USBH_TYPE == USBH_OHCI_TYPE)
#define JPEG_FRONT_OUTPUT_BUFFER_CNT			24	// JPEG Output Buffer
#define JPEG_FRONT_OUTPUT_BUFFER_SIZE			(130 * 1024)
#else
#define JPEG_FRONT_OUTPUT_BUFFER_CNT			19	// JPEG Output Buffer
#define JPEG_FRONT_OUTPUT_BUFFER_SIZE			(120 * 1024)
#endif

#define JPEG_FRONT_OUTPUT_BUFFER_CNT_1080		13	// JPEG Output Buffer
#define JPEG_FRONT_OUTPUT_BUFFER_SIZE_1080		(190 * 1024)

#define JPEG_PCCAM_OUTPUT_BUFFER_CNT			3	// JPEG Output Buffer
#define JPEG_PCCAM_OUTPUT_BUFFER_SIZE			(200 * 1024)

#define JPEG_FRONT_MOTOR_OUTPUT_BUFFER_CNT		28	// JPEG Output Buffer
#define JPEG_FRONT_MOTOR_OUTPUT_BUFFER_SIZE		(75 * 1024)


#define JPEG_FRONT_CAPTURE_OUTPUT_BUFFER_CNT	2
#define JPEG_FRONT_CAPTURE_OUTPUT_BUFFER_SIZE	(700 * 1024)

// REAR
#if ENABLE_REAR_FUNC
// Not more than front
#define FIFO_REAR_OUTPUT_BUFFER_CNT			6

#if (USBH_TYPE == USBH_OHCI_TYPE)
#define JPEG_REAR_OUTPUT_BUFFER_SIZE			(40 * 1024)
#define JPEG_REAR_OUTPUT_BUFFER_CNT				16	// JPEG Output Buffer
#elif (USBH_TYPE == USBH_EHCI_TYPE)
#define JPEG_REAR_OUTPUT_BUFFER_SIZE			(150 * 1024)//(150 * 1024)  130

#if C_REAR_ONLY == CUSTOM_OFF
#define JPEG_REAR_OUTPUT_BUFFER_CNT				18	// JPEG Output Buffer
#else
#define JPEG_REAR_OUTPUT_BUFFER_CNT				12//19//20///30	// JPEG Output Buffer
#endif

#endif

#if ENABLE_REAR_SENSOR_FROM_HOST_UVC
#define JPEG_REAR_CAPTURE_OUTPUT_BUFFER_CNT		2
#define JPEG_REAR_CAPTURE_OUTPUT_BUFFER_SIZE	   (75 * 1024)
#else
#define JPEG_REAR_CAPTURE_OUTPUT_BUFFER_CNT		2
#define JPEG_REAR_CAPTURE_OUTPUT_BUFFER_SIZE	 (10 * 1024)
#endif
#endif
#define DEBUG_CAPTURE_PHOTO_JPEG_SIZE	        (100 * 1024)
enum
{
	JPEG_SEND_TO_NOTHING,
	JPEG_SEND_TO_RECORD,
	JPEG_SEND_TO_PCCAM,
	JPEG_SEND_TO_PHOTO
};
enum
{
	VIDEO_RECORD_NOTHING,
	VIDEO_RECORD_START			= 0x01,
	VIDEO_RECORD_RECING			= 0x02,
	VIDEO_RECORD_STOP			= 0x04,
	VIDEO_RECORD_PHOTO_START	= 0x08,
	VIDEO_RECORD_PHOTO			= 0x10
};

/**************************************************************************
 *                           D A T A  T Y P E S                           *
 **************************************************************************/
typedef struct preview_args_s
{
	INT16U	clip_width;
	INT16U	clip_height;
	INT16U	sensor_width;
	INT16U	sensor_height;
	INT16U	zoom_width;
	INT16U	zoom_height;
	INT16U	zoom_w_start;
	INT16U	zoom_h_start;
	INT16U	zoom_width_r;
	INT16U	zoom_height_r;
	INT16U	zoom_w_start_r;
	INT16U	zoom_h_start_r;	
	INT16U	display_width;
	INT16U	display_height;
	INT16U	display_offset;
	INT32U	display_buffer_addrs;
	INT32U	(*display_buffer_pointer_get) (void);
	INT32S	(*display_buffer_pointer_put) (INT32U * queue, INT32U addr);
	void	(*display_frame_ready_notify) (INT32U display_buffer_addrs);
	INT16U	run_ap_mode;

	INT16U	sensor_width_r;
	INT16U	sensor_height_r;

	INT16U	pip_x;
	INT16U	pip_y;
	INT16U	pip_width;
	INT16U	pip_height;
} preview_args_t;

typedef struct FIFO_COMPRESS_ARGS_S
{
	void (*jpeg_status_notify) (INT32S eventMsg, INT32U vlcCount);
	AVIPACKER_FRAME_INFO	*pJpeg_output_addrs;
	INT32U	jpeg_output_addrs_max_count;
	INT32U	jpeg_output_addrs_max_size;
	INT32U	jpeg_output_addrs_idx;
	INT32U	fifo_compress_next_addrs;
	INT32U	fifo_compress_count;
	INT32U	fifo_compress_max_count;
	INT32U	fifo_compress_data_size;
	INT32U	fifo_compress_line_size;
	INT32S	fifo_compress_vlc_max_size;
	INT32U	jpeg_img_width;
	INT32U	jpeg_img_height;
	INT32U	target_Y_Q_value;
	INT32U	target_UV_Q_value;
	INT32U	timestamp_start_idx;
	INT32U	timestamp_end_idx;
	INT32U	use_total_fifo_count;
	INT32U	use_SDRAM_fifo_count;
	INT8U	jpeg_header_restart_interval_idx;
	INT8U	jpeg_img_format;
	INT8U	jpeg_new_buffer_get;
	INT8U	jpeg_scale_up;
	INT8U	skip_this_one;
	INT8U	jpeg_dev_num;
} FIFO_COMPRESS_ARGS;

typedef struct JPEG_COMPRESS_ARGS_S
{
	FIFO_COMPRESS_ARGS	jpeg_front_info;

#if ENABLE_REAR_FUNC
	FIFO_COMPRESS_ARGS	jpeg_rear_info;
#endif
	INT32U	jpeg_input_data_addrs;
	INT32U	jpeg_input_data_addrs_rear;
	INT32S	jpeg_vlc_size;
	INT32U	jpeg_compress_src;
	INT32U	jpeg_send_to_target;
	INT32U	jpeg_engine_status;
	INT32S	jpeg_vlc_size_rear;

	#if ENABLE_DOUBLE_JPEG
	INT32U	jpeg_engine_status_rear;
	#endif
} JPEG_COMPRESS_ARGS;

extern PREVIEW_MODE preview_mode;
extern INT32U	front_sensor_frm_cnt;
extern INT8U	front_sensor_err_handle_en;


/****************************************************************************/
extern void		DateTimeBufUpdate(void);
extern void		cpu_draw_time_osd(INT32U target_buffer, INT8U draw_type, INT8U state, INT32U ImgWidth, INT32U ImgHeight);
extern INT32S	video_preview_mode_set(PREVIEW_MODE mode);
extern INT32S	video_preview_start(preview_args_t *pPreviewArgs);
extern INT32S	video_preview_stop(void);

extern void		front_encode_param_set(JPEG_COMPRESS_ARGS *pJpegCompressArgs);
extern void		front_jpeg_Q_dynamic_tune(INT32U *pRetYQ, INT32U *pRetUVQ, INT32U vlcSize);

extern void		front_capture_param_set(JPEG_COMPRESS_ARGS *pJpegCompressArgs);

#if ENABLE_REAR_FUNC
extern void		record_encode_fifo_notify(VID_REC_ARGS *pRecArgs, INT32U fifoAddrs);
extern INT32S	video_recording_start(VID_REC_ARGS *pVidRecArgs, VID_REC_ARGS *pRearVidRecArgs);
extern void		rear_encode_param_set(JPEG_COMPRESS_ARGS *pJpegCompressArgs);
extern void		rear_jpeg_Q_dynamic_tune(INT32U *pRetYQ, INT32U *pRetUVQ, INT32U vlcSize);
extern INT32S	image_capture_start(IMG_CAPTURE_ARGS *pImgCaptureArgs, IMG_CAPTURE_ARGS *pRearImgCaptureArgs);
extern void		rear_capture_param_set(JPEG_COMPRESS_ARGS *pJpegCompressArgs);
extern void		cdsp_idle_isr(void);
#else // #if ENABLE_REAR_FUNC
extern INT32S	video_recording_start(VID_REC_ARGS *pVidRecArgs);
extern INT32S	image_capture_start(IMG_CAPTURE_ARGS *pImgCaptureArgs);
#endif // #if ENABLE_REAR_FUNC

#if ENABLE_REAR_SENSOR_FROM_HOST_UVC
extern INT32S	uvc_q_put_idle(INT32U buf);
extern INT32S	uvc_q_get_idle(INT32U *buf);
extern INT32S	uvc_q_put_ready(INT32U buf, INT32U size);
extern INT32S	uvc_q_get_ready(INT32U *buf, INT32U *size);
extern INT8U	uvc_q_ready_is_empty(void);
extern INT32S	uvc_q_init(void);
extern INT32S	uvc_q_uninit(void);
extern INT32S	uvc_q_reinit(void);
#endif // ENABLE_REAR_SENSOR_FROM_HOST_UVC

extern INT32S	encode_q_put_idle(INT32U buf);
extern INT32S	encode_q_get_idle(INT32U *buf);
extern INT32S	encode_q_put_ready(INT32U buf);
extern INT32S	encode_q_get_view(INT32U *buf);
extern INT32S	encode_q_get_encode(INT32U *buf);
extern INT32S	encode_q_put_preview(INT32U buf);
extern INT32S	encode_q_put_encode(INT32U buf);
extern INT32S	encode_q_init(void);
extern INT32S	encode_q_uninit(void);
#endif // __CALLBACK_VIDEO_CODEC_AVI_H__
